<?php


namespace app\models;

use Yii;
class RedisCache
{
    public static function set ($name,$data) {
        $cache = Yii::$app->cache;
        if (isset($name) || isset($data)){
            $str = json_encode($data);
            $cache->set($name,$str,3600*23);
            return true;
        }else{
            return false;
        }
    }

    public static function can ($name) {
        $cache = Yii::$app->cache;
        $str = base64_decode($name);
        if (!$cache->get($str)){
            $user = Information::find()->where(['alias'=>$str])->asArray()->one();
            $data = [
                'name'=>$user['alias'],
                'address'=>$user['address'],
                'Short'=>$user['Short'],
                'Shortie'=>$user['Shortie'],
                'type'=>$user['type'],
                'time'=>$user['time']
            ];
            self::set($str,$data);
        }else{
            $data = json_decode($cache->get($str),true);
        }
        return $data;
    }
}